package io_std

import (
	"clean/usecase/io/pb"
	"net/http"
	"net/url"
)

func (r *Handler) Hello(w http.ResponseWriter, req *http.Request) {
	u, err := url.ParseRequestURI(req.RequestURI)
	if err != nil {
		w.Write([]byte(err.Error()))
		return
	}
	name := u.Query().Get("name")
	in := pb.Input{
		Msg: &pb.Input_InputHello{
			InputHello: &pb.InputHello{
				Name: name,
			},
		},
	}
	out := &pb.Output{}
	r.app.Hello(in, out)
	if out.Error != nil {
		w.Write([]byte(out.Error.Msg))
		return
	}
	w.Write([]byte(out.GetOutputHello().Msg))
}
